package com.hwy.catering.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hwy.catering.dto.MealDto;
import com.hwy.catering.entity.Dish;
import com.hwy.catering.entity.Meal;
import com.hwy.catering.service.MealService;
import com.hwy.catering.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "套餐管理接口")
@RestController
@RequestMapping("/cater/meal")
public class MealController {

    @Resource
    private MealService mealService;

    @ApiOperation("具体删除套餐")
    @PostMapping("/deleteOneMeal/{id}")
    public R deleteOneMeal(@PathVariable Long id){
        R r = mealService.deleteOneMeal(id);
        return r;
    }

    @ApiOperation("编辑套餐")
    @PostMapping("/editMeal")
    public R editMeal(@RequestBody MealDto mealDto) {
        R r = mealService.editMeal(mealDto);
        return r;
    }

    @ApiOperation("获取单个套餐详情")
    @GetMapping("/getMealById/{id}")
    public R getMealById(@PathVariable Long id){
        R r = mealService.getMealById(id);
        return r;
    }

    @ApiOperation("查询所有套餐")
    @PostMapping("findMealAll/{page}/{limit}")
    public R findMealAll(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit,
            @RequestBody Meal meal){
        Page<Meal> pageParam = new Page<>(page, limit);
        R r = mealService.findMealAll(pageParam,meal);
        return r;
    }

    @ApiOperation("添加套餐")
    @PostMapping("/addMeal")
    public R addMeal(@RequestBody MealDto mealDto) {
        R r = mealService.addMeal(mealDto);
        return r;
    }
}
